/*
 * Plan.java
 * Created on March 25, 2007, 6:10 PM
 * $Id: Degree.java 41 2007-03-25 16:39:13Z dwight $
 */

package CSIS543TFinalProject;

import CSIS543TFinalProject.db.DbHelper;
import java.util.ArrayList;
import java.util.List;

/**
 a Plan consists of the courses the student wants to take, and *when* they plan
 on taking the courses. we maintain a list of ScheduledCourse items.
 * @author dwight fellman
 */
public class Plan {
   private String degreeName;
   private List <ScheduledCourse> scheduledCourses = new ArrayList <ScheduledCourse> ();
   
   /**
    for the given Degree, create a new Plan object. This can happen when the
    user selected a new Degree in the GUI.
    */
   public Plan(Degree degree) {
      this.degreeName = degree.getName();
      for (Course c : degree.getRequiredCourses()){
         scheduledCourses.add(new ScheduledCourse(c.getName()));
      }
   }
   
   /**
    remove the course from this Plan for the given course name.
    */
   public void removeCourse(String courseName) {
      for (ScheduledCourse sc : scheduledCourses) {
         if (sc.getCourseName().equals(courseName)) {
            scheduledCourses.remove(sc);
            return;
         }
      }
   }
   
   /**
    return TRUE if this Plan contains the given course name.
    */
   public boolean PlanHasCourse(String courseName) {
      for (ScheduledCourse sc : scheduledCourses) {
         if (sc.getCourseName().equals(courseName)) {
            return true;
         }
      }
      return false;
   }
   
   /**
    user wants to add another course to the plan. just add it. user can check
    pre-reqs via a button. we check for dupes here; return FALSE if course not
    added.
    */
   public boolean AddCourse(String courseName) {
      if (!PlanHasCourse(courseName)) {
         scheduledCourses.add(new ScheduledCourse(courseName));
         return true;
      }
      return false;
   }
   
   public int getCurrentCourseCount() {
      return scheduledCourses.size();
   }
   
   public int getCurrentCreditCount() {
      DbHelper dbh = new DbHelper();
      int courseCredits = 0;
      for (ScheduledCourse sc : this.scheduledCourses) {
         String courseName = sc.getCourseName();
         Course c = dbh.GetCourse(courseName);
         courseCredits += c.getCredits();
      }
      dbh.close();
      return courseCredits;
   }
   
   public Plan(String degreeName) {
      this.setDegreeName(degreeName);
   }
   
   public String getDegreeName() {
      return degreeName;
   }
   
   public void setDegreeName(String degreeName) {
      this.degreeName = degreeName;
   }
   
   public List<ScheduledCourse> getScheduledCourses() {
      return scheduledCourses;
   }
   
   public void setScheduledCourses(List<ScheduledCourse> scheduledCourses) {
      this.scheduledCourses = scheduledCourses;
   }
}


